//
//  PKLiveConfigViewController.swift
//  Panku
//
//  Created by mac on 2017/4/28.
//  Copyright © 2017年 Monster. All rights reserved.
//

import UIKit
import SnapKit

private let PKLiveConfigViewControllerCellID = "PKLiveConfigViewControllerCellID"

class PKLiveConfigViewController: PKBaseViewController {
    
    //MARK: - init
    init(viewModel:PKLiveConfigViewModel){
        self.viewModel = viewModel
        super.init(nibName: nil, bundle: nil)
        
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //viewModel
    var viewModel:PKLiveConfigViewModel?
    
    
    lazy var tableView:PKBaseTableView = PKBaseTableView(frame: CGRect.zero, style: .grouped)
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }
    
    override func setupRootView() {
        //title
        self.title = "直播设置"
    }
    
    override func setupSubViews() {
        view.addSubview(tableView)
        
        tableView.dataSource = self
        tableView.delegate = self
        
        tableView.register(UITableViewCell.self, forCellReuseIdentifier: PKLiveConfigViewControllerCellID)
    }
    
    override func setupSubViewsConstraints() {
        tableView.snp.makeConstraints { (make) in
            make.edges.equalTo(view)
        }
    }
    
    override func setupNavigationBar() {
        
    }
    
    override func bindViewModel() {
        
    }



}

extension PKLiveConfigViewController:UITableViewDataSource,UITableViewDelegate{
    func numberOfSections(in tableView: UITableView) -> Int {
        return viewModel!.numberOfSections()
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return viewModel!.numberOfRowsInSection(section: section)
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: PKLiveConfigViewControllerCellID, for: indexPath)
        
        //推送switch
        if indexPath == IndexPath(row: 0, section: 0) {
            let enbaleNotification = UISwitch()
            cell.accessoryView = enbaleNotification
        }else{
            let enableMessage = UISwitch()
            cell.accessoryView = enableMessage
        }
        
        return cell
    }
    
    func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        cell.textLabel?.text = viewModel?.titleForIndexPath(indexPath: indexPath)
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
        //设置deselect动画
        tableView.deselectRow(at: indexPath, animated: true)

    }
}
